#include "glut.h"
#include "V2D.h"
#include "rect.h"

/**
 * handles data & methods related to screen size and cartesian formatting
 * the rendering-context is a rectangle in cartesian space
 * @author mvaganov@hotmail.com August 2010
 */
struct GLUTRenderingContext : public RectF
{
	/** how many pixels wide and tall the screen is */
	V2DF dimensionPixels;

	/**
	 * @param a_dimensionPixels pixel width/height
	 * @param a_min cartesian minimum
	 * @param a_max cartesian maximum
	 */
	inline GLUTRenderingContext(const V2DF & a_dimensionPixels, 
		const V2DF & a_min, const V2DF & a_max)
		:dimensionPixels(a_dimensionPixels),RectF(a_min,a_max)
	{}

	/** sets up the openGL screen according to current variables */
	void glSetupScreen();

	/** sets up the cartesian plane for openGL/GLUT */
	void ortho2D();

	/** 
	 * @param a_position x/y in pixels (like from a mouse press) 
	 * @return cartesian coordinate equivalent
	 */
	V2DF convertPixelsToCartesian(const V2DF & a_position) const;

	/**
	 * resizes the image for the cartesian plane
	 */
	void reshape(int a_widthPixels, int a_heightPixels);

	/**
	 * draw the cartesian plane 
	 * @param a_dashSize how big to make the unit marks (sample value: 0.1)
	 */
	void glDraw(float a_dashSize);
};
